﻿using AttributeRouting.Web.Mvc;
using Childhood.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;

namespace Childhood.Controllers
{
    public partial class AboutDetailController : Controller
    {
        //
        // GET: /AboutDetail/
        childhoodDiariesEntities _entity = new childhoodDiariesEntities();

        [GET("thong-tin/{footerCategory?}/{footer?}")]
        public virtual ActionResult Index(string footerCategory, string footer,int? page)
        {
            try
            {
                if (footerCategory != null && footer != null)
                {
                    var detail = _entity.tblFooter.Where(d => d.C_url.Trim().ToLower() == (footerCategory + "/" + footer).Trim().ToLower()).FirstOrDefault();
                    if(detail!=null){
                        var lstOther = _entity.tblFooter.Where(d => d.C_id != detail.C_id).ToList();
                        var pageNumber = page ?? 1; // if no page was specified in the querystring, default to the first page (1)
                        var onePageOfOtherFooter = lstOther.ToPagedList(pageNumber, 10); // will only contain 10 products max because of the pageSize;
                        ViewBag.OtherFooterInfor = lstOther;
                        ViewBag.onePageOfOtherFooter = onePageOfOtherFooter;
                    }
                    return View(detail);
                }
                else
                {
                    return RedirectToAction("Index", "Error", new { statusCode = 404, lastError = new NullReferenceException(), isAjaxRequet = false });
                }
            }
            catch (Exception ex)
            {
                return RedirectToAction("Index", "Error", new { statusCode = 404, lastError = ex, isAjaxRequet = false });
            }
        }

    }
}
